package com.xiaohongshu.kafkademo.controller;


import com.xiaohongshu.kafkademo.service.AsyncService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/book")
@Slf4j
public class AsnycController {

    @Resource
    private AsyncService asyncService;

    @GetMapping("/async-test")
    public String testAsync() {
        log.info("开始异步调用: " + Thread.currentThread().getName());

        // 异步调用，不会阻塞
        asyncService.processDataAsync("测试数据1");
        asyncService.processDataAsync("测试数据2");
        asyncService.sendEmailAsync("user@example.com",  "异步邮件内容");

        System.out.println("异步调用结束: " + Thread.currentThread().getName());
        return "异步任务已提交";
    }
}
